﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Sec_scan指纹识别系统
{
    /// <summary>
    /// 指纹识别扫描公共方法
    /// </summary>
    public class Sec_ScanInfoSDb
    {
        /// <summary>
        /// 扫描基于WEB的指纹
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static string ScanInfo(string info)
        {
            Sec_scanDbOpenApi.OpenName = new StringBuilder();
            string url = "http://219.239.52.24:1611/";
            try
            {
                HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(url + Sec_scanDbOpenApi.SecPath.ToString());//需要加tostring 否则无法读取过来，动态字段
                httpReq.Method = "GET";//获取请求方式
                httpReq.Accept = "*/*";
                httpReq.ServicePoint.Expect100Continue = false;//加快载入速度
                httpReq.ServicePoint.UseNagleAlgorithm = false;//禁止nagle算法加快载入速度
                httpReq.AllowWriteStreamBuffering = false;//禁止缓冲加快载入速度
                httpReq.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");//定义gzip压缩页面支持
                httpReq.ContentType = "application/x-www-form-urlencoded";//定义文档类型及编码
                httpReq.AllowAutoRedirect = false;//禁止自动跳转
                httpReq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
                httpReq.Timeout = 2000;//请求超时
                httpReq.KeepAlive = true;//启用长连接
                httpReq.ServicePoint.ConnectionLimit = int.MaxValue;//定义最大连接数
                HttpWebResponse response = (HttpWebResponse)httpReq.GetResponse();
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding("UTF-8"));
                string html = readStream.ReadToEnd();
                string sload = html;//获取源代码
                for (int i = 0; i < 1; i++)
                {
                    if (System.Text.RegularExpressions.Regex.IsMatch(sload, Sec_scanDbOpenApi.SecKey.ToString()))//key是关键特征
                    {
                        if (html.Length >= 1)
                        {
                            string s8 = Sec_scanDbOpenApi.SecName.ToString();
                            Sec_scanDbOpenApi.OpenName.Append(Sec_scanDbOpenApi.SecName.ToString());
                            //ZscanInfo();
                            //MessageBox.Show("存在关键特征：" + key);
                        }
                    }
                    else
                    {
                        //Console.WriteLine("创建时间：" + DateTime.Now + "识别路径：" + url + paths + "  ---  " + "无法识别WEB容器" + "\r\n");
                        //ZscanInfo();
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show("123");
                //Console.WriteLine(richTextBox1.Text += "创建时间：" + DateTime.Now + "识别路径：" + url + paths + "  ---  " + "无法识别WEB容器" + "\r\n");
            }
            return info;
        }
    }
}
